/**
 * Write a program that gives count of common characters presented in an array
 * of strings..(or array of character arrays)
 * 
 * For eg.. for the following input strings..
 * 
 * aghkafgklt
 * dfghako
 * qwemnaarkf
 * 
 * The output should be 3. because the characters a, f and k are present in all
 * 3 strings.
 * 
 * Note: The input strings contains only lower case alphabets
 * 
 * @author ruinvepc http://www.careercup.com/question?id=6283084039192576
 */
public class CommonChars {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println("Number = " + new CommonChars().getNumberOfCommon(new String[]{"abcyz", "ydbaa", "qurat"}));

    }

    public int getNumberOfCommon(String[] strings)
    {
        int res = Integer.MAX_VALUE;
        for(String str: strings)
        {
            int bitstring = 0;
            for (int i = 0; i < str.length(); i++)
            {
                bitstring |= 1 << getPosition(str.charAt(i));
            }
            res &= bitstring;
        }
        return Integer.bitCount(res);
    }

    // calculate position in your alphabet
    private int getPosition(char c)
    {
        return c - 'a';
    }

}
